require(['loading'], function(loading) {
	//获取url中的id参数
	var params = getUrlParams();
	var detailId = params.id?params.id:"";
	var isFollow;
    //实例化
    var detail = new Vue({
        el: '#detail',
        data: {
            bulkData: '',
            showLoading: false,
            apiUrl: wxUrl + '/v3.2/ttrader/detail.do',
            followUrl:wxUrl + '/v3.2/follow/trader',
            item: {
                params:{
                    token: token,
                    userToken: userToken,
                    id:detailId 
                }
            },
            itemFollow: {
                params:{
                    token: token,
                    userToken: userToken,
                    traderId:detailId ,
                    action: ''
                }
            }
        },
        ready: function(){
            this.getIndexData()
        },
        methods: {
            getIndexData: function() {
                this.$http.get(this.apiUrl, this.item)
                .then(function(response) {
                    var result = JSON.parse(response.body);
                    console.log(result)
                    this.bulkData = result.data.result;
                    isFollow = result.data.result.isFollow;
                    if(isFollow == '0'){
                       $(".guanzhu span").text("关注TA");
                       $(".guanzhu img").attr("src","../static/images/fqguanzhu.png");
                    }else if(isFollow == '1'){
                        $(".guanzhu span").text("已关注");
                        $(".guanzhu img").attr("src","../static/images/fqygz.png");
                    }
                });
            },
            getFollow:function(){
            	if(vLoginClick()){
	            	if(isFollow == '0'){
	            		this.itemFollow.params.action = 1;
	            		this.$http.get(this.followUrl,this.itemFollow)
	                    .then(function(response){
	                    	var result = JSON.parse(response.body);
	                        var success =  result.data.success;
	                        if(success){
	                        	promptBox("关注成功");
	                            $(".guanzhu span").text("已关注");
	                            $(".guanzhu img").attr("src","../static/images/fqygz.png");
	                            isFollow = '1';
	                        }
	                    });
	            	}else{
	            		this.itemFollow.params.action = 0;
	            		this.$http.get(this.followUrl,this.itemFollow)
	                    .then(function(response){
	                    	var result = JSON.parse(response.body);
	                        var success =  result.data.success;
	                        if(success){
	                        	promptBox("已取消关注");
	                            $(".guanzhu span").text("关注TA");
	                            $(".guanzhu img").attr("src","../static/images/fqguanzhu.png");
	                            isFollow = '0';
	                        }
	                    });
	            	}
                }
            }
        }
    });
});
$(function(){
	$('#showEwm').click(function(){
		$('#shadow').show();
		$('#ewmTc').show();
	});
	$('#shadow').click(function(){
		$('#shadow').hide();
		$('#ewmTc').hide();
	});
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});